﻿using System.Collections.Generic;
using System.Diagnostics;

namespace HostsUpdater {

    public class NSLookup {
        private string _address;
        private string _domain;
        private IList<string> _result;

        public string Domain {
            get {
                return _domain;
            }
            set {
                _domain = value;
            }
        }

        public IList<string> Result {
            get {
                return _result;
            }
            set {
                _result = value;
            }
        }

        public NSLookup(string address) {
            _result = new List<string>();
            _address = address;
        }

        public string Lookup() {
            string output = string.Empty;
            Process process = new Process();
            ProcessStartInfo processStartInfo = new ProcessStartInfo();
            processStartInfo.FileName = "nslookup.exe";
            processStartInfo.Arguments = string.Join(" ", new string[] { "-vc", Domain, _address });
            processStartInfo.UseShellExecute = false;
            processStartInfo.RedirectStandardOutput = true;
            process.StartInfo = processStartInfo;
            process.Start();
            output = process.StandardOutput.ReadToEnd();

            return output;
        }
    }
}
